package com.bruce.springbootDemo.web.controller;

import com.bruce.springbootDemo.annotation.PathRestController;
import com.bruce.springbootDemo.annotation.Permission;
import com.bruce.springbootDemo.annotation.UserRoleEnum;
import com.bruce.springbootDemo.model.entity.TUser;
import com.bruce.springbootDemo.web.restFul.ResponseEntity;
import com.bruce.springbootDemo.web.restFul.ResponseTool;
import com.bruce.springbootDemo.web.service.IUserService;
import com.bruce.springbootDemo.utils.IdGeneratorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.UUID;

/**
 * Created by bruce on 18/11/22 -- 14:43
 */
@PathRestController(value = "/user")
public class UserController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    @Qualifier(value = "UserServiceImpl")
    private IUserService userService;

    @PostMapping("/login")
    public ResponseEntity login(@RequestParam String name, @RequestParam String password) throws Exception {
        TUser tUser = new TUser();
        String cacheName = userService.fetchName(name);
        tUser.setName(cacheName);
        return ResponseTool.ok(tUser);
    }

    @GetMapping("/test")
    @Permission(UserRoleEnum.ADMIN)
    public ResponseEntity test() {
        IdGeneratorUtil generator = new IdGeneratorUtil();
        UUID uuid = generator.generateId();
        logger.info("test>>" + uuid);
        return ResponseTool.ok();
    }
}
